package com.cash.loan.modular.cash.service.impl;

import com.cash.loan.common.upload.QiniuService;
import com.cash.loan.modular.cash.dao.ProductAdPictureMapper;
import com.cash.loan.modular.cash.model.ProductAdPicture;
import com.cash.loan.modular.cash.service.AdService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Administrator
 * @description
 * @date 2018年10月02 19:19
 */
@Service
public class AdServiceImpl extends CommonService implements AdService {

    private static final Integer UI_TYPE = 2;

    @Autowired
    private ProductAdPictureMapper productAdPictureMapper;

    @Autowired
    private QiniuService qiniuService;

    @Override
    public Map<String, Object> getAdInfoByType(String type,Integer uiType) {
        ProductAdPicture productAdPicture = productAdPictureMapper.getUsedLimitAd(type);
        Map<String,Object> result = new HashMap<>(6);

        if(productAdPicture == null) {
            return new HashMap<>(1);
        }

        if(UI_TYPE.equals(uiType)) {
            if(isDownloadProductAd(productAdPicture.getProductId())) {
                productAdPicture = null;
            }
            if(productAdPicture == null) {
                return new HashMap<>(1);
            }
        }

        result.put("productId",productAdPicture.getProductId());
        result.put("adImgUrl",qiniuService.getUrl(productAdPicture.getAdImgUrl()));
        if(StringUtils.isNoneBlank(productAdPicture.getAdProductH5Url())) {
            result.put("adProductH5Url",productAdPicture.getAdProductH5Url());
        } else {
            result.put("adProductH5Url","");
        }

        return result;
    }
}
